package com.manage.project.biz.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.framework.aspectj.lang.annotation.Log;
import com.manage.framework.aspectj.lang.enums.BusinessType;
import com.manage.framework.web.controller.BaseController;
import com.manage.framework.web.domain.AjaxResult;
import com.manage.framework.web.page.TableDataInfo;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.project.biz.domain.BizXiaofangyanghu;
import com.manage.project.biz.service.IBizXiaofangyanghuService;
import com.manage.project.biz.domain.BizGonglu;
import com.manage.project.biz.domain.BizSuidao;
import com.manage.project.biz.service.IBizGongluService;
import com.manage.project.biz.service.IBizSuidaoService;

/**
 * 消防设施清洁维护Controller
 *
 * @author liang
 * @date 2022-06-02
 */
@RestController
@RequestMapping("/biz/xiaofangyanghu")
public class BizXiaofangyanghuController extends BaseController
{
    @Autowired
    private IBizXiaofangyanghuService bizXiaofangyanghuService;

    @Autowired
    private IBizSuidaoService bizSuidaoService;

    @Autowired
    private IBizGongluService bizGongluService;
    /**
     * 查询消防设施清洁维护列表
     */
    @PreAuthorize("@ss.hasPermi('biz:xiaofangyanghu:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizXiaofangyanghu bizXiaofangyanghu)
    {
        startPage();
        List<BizXiaofangyanghu> list = bizXiaofangyanghuService.selectBizXiaofangyanghuList(bizXiaofangyanghu);
        return getDataTable(list);
    }
    @GetMapping("/level")
    public TableDataInfo getLevel(BizXiaofangyanghu bizXiaofangyanghu)
    {
        List<String> list = new ArrayList<>();
        String tunnelName = bizXiaofangyanghu.getField1();
        if (tunnelName == null){
            return getDataTable(list);
        }
        BizSuidao bizSuidao = new BizSuidao();
        bizSuidao.setField2(tunnelName);
        List<BizSuidao> listSuidao = bizSuidaoService.selectBizSuidaoList(bizSuidao);
        long tunnelLength = Long.parseLong(listSuidao.get(0).getField5());// 隧道长度
        long tunnelCars = Long.parseLong(listSuidao.get(0).getField18()); // 隧道年日均交通量
        BizGonglu bizGonglu = new BizGonglu();
        bizGonglu.setField2(listSuidao.get(0).getField22());
        List<BizGonglu> listBizGonglu = bizGongluService.selectBizGongluList(bizGonglu);
        String gongluLevel = listBizGonglu.get(0).getField9(); // 公路等级
        if (gongluLevel.equals("一级")){
            if (tunnelCars>=10001){
                if (tunnelLength>3000){
                    list.add("一级");
                } else if (tunnelLength>1000 && tunnelLength<=3000){
                    list.add("一级");
                } else if (tunnelLength>500 && tunnelLength<=1000){
                    list.add("一级");
                } else if (tunnelLength<=500){
                    list.add("二级");
                }
            } else if (tunnelCars>=5001){
                if (tunnelLength>3000){
                    list.add("一级");
                } else if (tunnelLength>1000 && tunnelLength<=3000){
                    list.add("一级");
                } else if (tunnelLength>500 && tunnelLength<=1000){
                    list.add("二级");
                } else if (tunnelLength<=500){
                    list.add("二级");
                }
            } else {
                if (tunnelLength>3000){
                    list.add("一级");
                } else if (tunnelLength>1000 && tunnelLength<=3000){
                    list.add("二级");
                } else if (tunnelLength>500 && tunnelLength<=1000){
                    list.add("二级");
                } else if (tunnelLength<=500){
                    list.add("二级");
                }
            }
        } else {
            if (tunnelCars>=10001){
                if (tunnelLength>3000){
                    list.add("一级");
                } else if (tunnelLength>1000 && tunnelLength<=3000){
                    list.add("二级");
                } else if (tunnelLength>500 && tunnelLength<=1000){
                    list.add("二级");
                } else if (tunnelLength<=500){
                    list.add("三级");
                }
            } else if (tunnelCars>=5001){
                if (tunnelLength>3000){
                    list.add("二级");
                } else if (tunnelLength>1000 && tunnelLength<=3000){
                    list.add("二级");
                } else if (tunnelLength>500 && tunnelLength<=1000){
                    list.add("三级");
                } else if (tunnelLength<=500){
                    list.add("三级");
                }
            } else {
                if (tunnelLength>3000){
                    list.add("二级");
                } else if (tunnelLength>1000 && tunnelLength<=3000){
                    list.add("三级");
                } else if (tunnelLength>500 && tunnelLength<=1000){
                    list.add("三级");
                } else if (tunnelLength<=500){
                    list.add("三级");
                }
            }
        }
        return getDataTable(list);
    }
    /**
     * 导出消防设施清洁维护列表
     */
    @PreAuthorize("@ss.hasPermi('biz:xiaofangyanghu:export')")
    @Log(title = "消防设施清洁维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizXiaofangyanghu bizXiaofangyanghu)
    {
        List<BizXiaofangyanghu> list = bizXiaofangyanghuService.selectBizXiaofangyanghuList(bizXiaofangyanghu);
        ExcelUtil<BizXiaofangyanghu> util = new ExcelUtil<BizXiaofangyanghu>(BizXiaofangyanghu.class);
        return util.exportExcel(list, "消防设施清洁维护数据");
    }

    /**
     * 获取消防设施清洁维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:xiaofangyanghu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizXiaofangyanghuService.selectBizXiaofangyanghuById(id));
    }

    /**
     * 新增消防设施清洁维护
     */
    @PreAuthorize("@ss.hasPermi('biz:xiaofangyanghu:add')")
    @Log(title = "消防设施清洁维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizXiaofangyanghu bizXiaofangyanghu)
    {
        return toAjax(bizXiaofangyanghuService.insertBizXiaofangyanghu(bizXiaofangyanghu));
    }

    /**
     * 修改消防设施清洁维护
     */
    @PreAuthorize("@ss.hasPermi('biz:xiaofangyanghu:edit')")
    @Log(title = "消防设施清洁维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizXiaofangyanghu bizXiaofangyanghu)
    {
        return toAjax(bizXiaofangyanghuService.updateBizXiaofangyanghu(bizXiaofangyanghu));
    }

    /**
     * 删除消防设施清洁维护
     */
    @PreAuthorize("@ss.hasPermi('biz:xiaofangyanghu:remove')")
    @Log(title = "消防设施清洁维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizXiaofangyanghuService.deleteBizXiaofangyanghuByIds(ids));
    }
}
